<?php
namespace App\Services;


use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

/**
 * 文件存储服务
 * Class FileStoreService
 * @package App\Services
 */
class FileStoreService
{

    private $auth;
    private $config;

    public function __construct()
    {
        $this->config = config('qiniu');

        $this->auth  = new Auth($this->config['accessKey'],$this->config['secretKey']);

    }

    public function save($filename, $filePath){

        $token = $this->auth->uploadToken($this->config['bucket']);

        $uploadMgr = new UploadManager();

        list($ret, $err) = $uploadMgr->putFile($token,$filename, $filePath);

        if($err !== null){
            return "";
        }

        return $this->config['domain'].$filename;
    }
}
